package model;

import exceptions.PointsOutOfReachException;
import java.util.ArrayList;
import settings.Settings;

/**
 * this class contains the player's information
 * @author HB
 *
 */
public class Player {
	
	/** - player name - */
	private String name;
	
	/** - points of each turn  - */
	private ArrayList<Integer> turns;

	/** - players current score - */
	private int currentScore;
	
	/** - true when player has won the game - */
	private Boolean win;
	
	/**
	 * constructor
	 * @param name
	 * @param maxScore
	 */
	public Player(String name){
		this.setName(name);
		this.turns = new ArrayList<Integer>();
		this.currentScore = Settings.MaxScore;
		this.win = false;
	}
	
	// setters 
	
	public void setName(String name){
		this.name = name;
	}
	
	public void setWin(boolean win){
		this.win = win;
	}
	
	private void addTurn(int points){
		Integer turn = new Integer(points);
		if (turn != null){
			turns.add(turn);
		}
	}
	
	//getters
	
	public String getName(){
		return this.name;
	}
	
	public int getCurrentScore(){
		return this.currentScore;
	}
	
	public boolean getWin(){
		return win;
	}
	
	public ArrayList<Integer> getTurns(){
		return turns;
	}
	
	
	/**
	 * when points in range substract from currentscore and add points to turn
	 * out of range throw exception
	 * @param points
	 */
	public void substractPoints(int points){
		try{
			if (points < 0 && points > Settings.maxThrow) throw new PointsOutOfReachException("Number must be above 0 and lower than or equal to 180");
			currentScore -= points;
			this.addTurn(points); 
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
	
	
}
